<?php
//售后
namespace app\adminbackstage\model;

use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class AfterSales extends Model{
    protected $type = [
        'img_json' => 'json',
    ];
    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }
    
    //售后列表
    public static function afterSalesList($where,$page,$num){
        $list = self::alias('a')
        ->field('a.*,u.username,u.phone,o.o_pro_num,o.p_num')
        ->leftjoin('user u','u.uid = a.uid')
        ->leftjoin('order o','o.id = a.oid')
        //->leftjoin('product p','p.id = a.pid')
        ->where($where)
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
    }
    
    //售后详情
    public static  function afterSalesInfo($where){
        $info = self::alias('a')
        ->field('a.*,u.username,u.phone,o.o_pro_num,o.p_num')
        ->leftjoin('user u','u.uid = a.uid')
        ->leftjoin('order o','o.id = a.oid')
       //->leftjoin('product p','p.id = a.pid')
        ->where($where)
        ->find();
        return $info;
    }
    
    //售后数
    public static function afterSalesCount($where) {
        return self::alias('a')
        ->field('a.*,u.username,u.phone')
        ->leftjoin('user u','u.uid = a.uid')
        ->leftjoin('order o','o.id = a.oid')
        //->leftjoin('product p','p.id = a.pid')
        ->where($where)
        ->count();
    }

    //售后修改
    public static function afterSalesEdit($id,$update){
        $in = self::update($update, ['id' => $id]);
        return $in;
    }
    

    //售后添加
    public static function afterSalesAdd(array $data){
        return self::create($data);
    }
    
    
    //售后单订单总数
    public static function afterSalesRq($where){
        return self::alias('a')
        ->leftjoin('user u','u.uid = a.uid')
        ->leftjoin('order o','o.id = a.oid')
       //->leftjoin('product p','p.id = a.pid')
        ->where($where)
        ->sum('a.as_rq');
    }
  
}
